package com.hqyj.module.InformationQuery.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.module.InformationQuery.dao.UserInformationMapper;
import com.hqyj.module.InformationQuery.entity.UserInfo;
import com.hqyj.module.InformationQuery.service.UserInformationService;
import com.hqyj.module.clock.pojo.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.Optional;

/**
 * @Description：UserInfoServiceImpl
 * @Author ：Cwd
 * @Date ：2021/10/8 10:06
 */
@Service
public class UserInformationServiceImpl implements UserInformationService {

    @Autowired
    private UserInformationMapper userInformationMapper;

    @Override
    public HashMap<String,Object> getUserInfoByUserName(String userName) {
        UserInfo userInfo = userInformationMapper.getUserInfoByUserName(userName);
        HashMap<String, Object> map = new HashMap<>();
        if (userInfo == null){
            map.put("info","获取个人信息失败");
        }else {
            map.put("info",userInfo);
        }
        return map;
    }

    @Override
    public PageInfo<UserInfo> getUsersBySearchBean(SearchBean myPage) {
        myPage.initSearchBean();
        PageHelper.startPage(myPage.getCurrentPage(), myPage.getPageSize());
        return new PageInfo<>(Optional
                .ofNullable(userInformationMapper.getUsersByMyPage(myPage))
                .orElse(Collections.emptyList()));
    }
}
